package 二叉树;

public class LC_404左叶子之和 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public int sumOfLeftLeaves(TreeNode root) {
        //后序遍历
        if(root==null) return 0;
        if(root.left==null && root.right==null)
            return 0;
        //左
        int leftnum=sumOfLeftLeaves(root.left);
        if(root.left!=null && root.left.left==null && root.left.right==null)
            leftnum=root.left.val;
        //右
        int rightnum=sumOfLeftLeaves(root.right);
        //中
        return rightnum+leftnum;
    }
}
